<?php
$title="Modify Recommend";
$css="modifyRecommend.css";
include_once 'common/AdminTop.php';
include_once 'authentic.php';
include_once '../Class/DB.php';
$db=new DB();
$rid=$_GET["id"];
$theRec=$db->get_rid_row($rid);
$theProduct=$db->get_pid_product($theRec["pid"]);
$theType=$db->get_tid_types($theProduct[0]["type"]);
$newPid=$_POST["good_id"];
$newPic=$_FILES["picurl"];
if(!isset($newPid))
{
	$newPid=$theRec["pid"];
}else if ($newPid=="")
{
	?>
	<script language="JavaScript">
	alert("Invalid Product Id!");
	window.location.href="others.php";
	</script>	
	<?php
	exit();
}else 
{
	$theNewProduct=$db->get_pid_product($newPid);
	if(!isset($theNewProduct[0]))
	{
	?>
	<script language="JavaScript">
	alert("Product Id doesn't exist!");
	window.location.href="others.php";
	</script>	
	<?php
	exit();
	}
}


if(isset($_POST["good_id"]))//press submit
{
	$db->update_recommend($rid,$newPid,$newPic);
	?>
	<script language="JavaScript">
	window.location.href="others.php";
	</script>	
	<?php
	exit();
}
?>
<div class="block_context" id="modify_block" align="center">
<p style="color:red">Recommend Details</p>
				<form enctype="multipart/form-data" action="modifyRecommend.php?id=<?php echo $rid;?>" method="post">
					<table>
						<tr>
							<th class="t1" style="width:150px">
							</th>
							<th class="t2">
							</th>	
						</tr>
						<tr>
						<td align="right"><b>Name:</b></td>
						<td align="left" style="padding-left:16px;"><b><?php echo $theProduct[0]["p_name"];?></b></td>
						</tr>
						<tr>
						<td align="right"><b>Type:</b></td>
						<td align="left" style="padding-left:16px;"><b><?php echo $theType[0]["name"];?></b></td>
						</tr>
						<tr>
						<td align="right"><b>Product ID:</b></td>
						<td align="left" style="padding-left:16px;"><input style="width:32px;" type="text" name="good_id" value="<?php echo $theRec["pid"];?>"/></td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>Path of Banner:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<input type="file" style="color:red;" name="picurl" />		
						</td>
						</tr>
					</table>
					<p><input type="submit" value="Save" />
						<input type="button" value="Return" onclick="window.location.href='others.php'";/>
						</p>
				</form>
			</div>
<?php 
include_once 'common/AdminTail.php';
?>